import { Component, OnInit, SkipSelf } from '@angular/core';
import { _isNumberValue, coerceBooleanProperty, coerceCssPixelValue} from '@angular/cdk/coercion';
import { CountService } from 'src/app/common/count/count.service';
@Component({
  selector: 'app-tools',
  templateUrl: './tools.component.html',
  styleUrls: ['./tools.component.scss'],
  providers: [CountService]
})
export class ToolsComponent implements OnInit {

  constructor(
    public count: CountService,
    @SkipSelf() public countParent: CountService
  ) { }

  ngOnInit(): void {
    console.log(_isNumberValue('12312312'));
    console.log(coerceBooleanProperty('false'));
    console.log(coerceCssPixelValue(12312312));
  }
  // 三个方法源码如下
  _isNumberValue(value: any): boolean {
    return !isNaN(parseFloat(value as any)) && !isNaN(Number(value));
  }
  coerceBooleanProperty(value: any): boolean {
    return value != null && `${value}` !== 'false';
  }
  /**
   * 输入number或者string
   * @param value string | number
   */
  coerceCssPixelValue(value: any): string {
    if (value == null) {
      return '';
    }
  
    return typeof value === 'string' ? value : `${value}px`;
  }
}
